//
//  NetworkRequest.h
//  CoachsBook
//
//  Created by huiyong li on 2022/9/2.
//

#import <Foundation/Foundation.h>
#import <AFNetworking.h>
#import "CBUser.h"
NS_ASSUME_NONNULL_BEGIN


typedef enum {
    NetWorkStateWifi,
    NetWorkStatePhone,
    NetWorkStateNone
}NetWorkState ;

typedef NS_ENUM(NSUInteger, RequestType) {
    GETType,
    POSTType,
    PUTType,
    DELETEType,
};

typedef enum {
    AMLogoutStatus, //no account login
    AMLoginStatus,  //account login
    AMLoginingStatus  //account is logining
} AMStatus;

//请求成功后的数据简单处理后的回调
typedef void (^SuccessBlock) (id result);
//请求失败后的响应及错误实例
typedef void (^FailureBlock) (NSError *error);
//失败后的响应及错误实例
typedef void (^FailBlock) (NSInteger code , NSString * msg);

@interface NetworkRequest : NSObject

/// 登录状态
@property (nonatomic, assign) AMStatus loginStatus;
@property (nonatomic, strong) AFHTTPSessionManager *afManager;



#pragma mark - 单例声明
+(instancetype)shareCommonRequest;


#pragma mark - 发起请求
/// @param path 请求地址
/// @param dict 请求参数
/// @param requestType 请求类型
/// @param completionBlock  成功返回
/// @param failureBlock 失败返回
/// @param failBlock 失败返回
- (void)startWithPath:(NSString *)path params:(nullable NSDictionary *)dict requestType:(RequestType)requestType sucess:(SuccessBlock)completionBlock FailureBlock:(FailureBlock)failureBlock failBlock :(FailBlock)failBlock;


#pragma mark -网络请求
/// @param params  请求参数
/// @param path 请求地址
/// @param requestType 请求类型
/// @param successBlock  成功返回
/// @param failBlock 失败返回
/// @param failure 失败返回
- (void)requestWithParams:(NSDictionary *)params Path:(NSString *)path requestType:(RequestType)requestType success:(SuccessBlock)successBlock fail:(FailBlock)failBlock failure:(void(^)(NSError *error))failure;

@end

NS_ASSUME_NONNULL_END
